# 纵横中文网
# 目录页爬取失败，每章标题返回为空


# 目录页

import requests
from lxml import etree

url = 'http://book.zongheng.com/showchapter/1091501.html'
headersvalue = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38'}
r = requests.get(url, headers = headersvalue)
code_type = r.apparent_encoding
if code_type == 'GB2312':
    code_type = 'GBK'
r.encoding = code_type
html = etree.HTML(r.text)
title = html.xpath('//li[@class=" col-4"]/@href')
print(title)

# 章节内容

import requests
import chardet
from lxml import etree
chapter_url = 'http://book.zongheng.com/chapter/1091501/64052299.html'
r = requests.get(chapter_url)
code_type = r.apparent_encoding
if code_type == 'GB2312':
    code_type = 'GBK'
r.encoding = code_type
html = etree.HTML(r.text)
contents = html.xpath('body/div//p/text()')

if contents[-1] == '捧场':
    contents.pop()
for c in contents:
    print('  ' + c + '\n')

